<template>
  <UploadOne
  ref="uploadOne"
    v-bind="$attrs"
    v-model="fileUrl"
    @beforeUpload="beforeUpload"
    :filesList='filesList'
    :isLocalFile="true"
  />
</template>

<script>
import UploadOne from './UploadOne'

export default {
  name: 'UploadLocal',
  components: {
    UploadOne
  },
  props: {
    value: null,
    // 回显文件
  },
  data() {
    return {
      fileUrl: '',
      file: null,
      filesList:[],
    }
  },
  watch: {
    value(val) {
      this.file = val
    },
    filesList(val){
      // console.log(val,"------->回显文件变化");
      this.fileUrl = val[0].url
    }
  },
  created() {},
  methods: {
    // 上传文件之前
    beforeUpload(file) {
      this.file = file
      this.$emit('input', file)
      this.fileUrl = this.getObjectURL(file)
    },

    // file文件转本地链接
    getObjectURL(file) {
      let url = null
      if (window.createObjcectURL != undefined) {
        url = window.createOjcectURL(file)
      } else if (window.URL != undefined) {
        url = window.URL.createObjectURL(file)
      } else if (window.webkitURL != undefined) {
        url = window.webkitURL.createObjectURL(file)
      }
      return url
    }
  }
}
</script>

<style lang="less" scoped>
</style>